from pyecharts import options as opts
from pyecharts.charts import Map
from app.dao.datasource import DataSource

pieces= [
      {"value": 0},
      {"min": 1, "max": 9,},
      {"min": 10, "max": 99},
      {"min": 100, "max": 499},
      {"min": 500, "max": 999},
      {"min": 1000, "max": 9999},
      {"min": 10000,},
    ]
class ProvinceMap(object):
    def __init__(self):
        ds = DataSource()
        self.c = Map(init_opts=opts.InitOpts(width='500px',chart_id='china_map')) \
            .add("当前确诊", [list(z) for z in zip(ds.df['name'], ds.df['nowConfirm'])], "china", ) \
            .add('累计确诊', [list(z) for z in zip(ds.df['name'], ds.df['confirm'])], "china") \
            .set_global_opts(\
            title_opts=opts.TitleOpts(title="疫情发布平台",title_textstyle_opts=opts.TextStyleOpts(color='#fff')),\
            legend_opts=opts.LegendOpts(selected_mode='single'),\
            visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pieces=pieces),\
            )
    def get_html(self):
        return self.c.render_embed()